Guarded _tx_thread_stack_analyze against inverted stack pointers - #727
Merged
Merged
Conversation
…er that is not above the start of the stack, so a stack overflow or a corrupted control block no longer hangs or crashes the caller _tx_thread_stack_analyze computed the midpoint of the remaining stack with TX_ULONG_POINTER_DIF, which casts the pointer difference to ULONG. When tx_thread_stack_highest_ptr had already moved below tx_thread_stack_start, the difference was negative and wrapped to a huge unsigned value, so the binary search probed far outside the stack and never converged. The highest stack pointer is now required to be above the start of the stack before the search begins, and the final scan for the first used word is bounded by the initial highest stack pointer so it cannot run past the end of the region either. Added regression coverage for an inverted and for an equal pair of stack pointers. Without the fix the new test case crashes the suite. Assisted-by: Copilot (Opus 5) <noreply@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #460
TX_ULONG_POINTER_DIFcasts the pointer difference toULONG, so whentx_thread_stack_highest_ptrsits belowtx_thread_stack_startthe midpointwraps to a huge value, the probe lands outside the stack, and the search never
converges: the caller hangs or faults.
_tx_thread_stack_analyzenow requires the highest pointer to be strictly abovethe start of the stack, and bounds the final scan by it. #464 covered the
TX_THREAD_STACK_CHECKpath; this covers direct callers too, as@billlamiework suggested on the issue.
Inconsistent pointers still mean a real overflow or a corrupted control block,
which remains the application's problem. What changes is that ThreadX reports it
through the stack error handler instead of hanging.
New cases for an inverted and an equal pointer pair crash the suite without the
fix and pass with it.